# 构建阶段
FROM node:22.19.0-alpine AS build
## 安装 pnpm
RUN npm install -g pnpm@10

## 环境变量
ARG VITE_API_BASE_URL
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL

WORKDIR /app
# 先复制包管理文件以利用缓存
COPY package.json pnpm-lock.yaml ./
# 安装依赖 (使用 frozen-lockfile 确保一致性)
RUN pnpm install --frozen-lockfile
# 复制项目文件并构建
COPY . .
RUN pnpm run build

# 生产阶段
FROM nginx:1.29.1-alpine-perl
# 移除默认配置
RUN rm /etc/nginx/conf.d/default.conf

COPY --from=build /app/dist /usr/share/nginx/html
COPY ./docker/nginx-default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]


